package com.bw.a2209clubshop.ui.mall.view

import android.content.Context
import android.content.Intent
import android.icu.text.IDNA
import android.os.Bundle
import android.widget.ImageView
import androidx.activity.enableEdgeToEdge
import androidx.activity.viewModels
import androidx.appcompat.app.AppCompatActivity
import androidx.core.view.ViewCompat
import androidx.core.view.WindowInsetsCompat
import com.alibaba.android.arouter.facade.annotation.Autowired
import com.bumptech.glide.Glide
import com.bw.a2209clubshop.IntentData
import com.bw.a2209clubshop.R
import com.bw.a2209clubshop.base.BaseToolbarActivity
import com.bw.a2209clubshop.databinding.ActivityGoodsDetailBinding
import com.bw.a2209clubshop.ui.mall.model.MallBanner
import com.bw.a2209clubshop.ui.mall.model.MallGoodsDetail
import com.bw.a2209clubshop.ui.mall.viewmodel.MallGoodsViewModel
import com.youth.banner.loader.ImageLoader
import dagger.hilt.android.AndroidEntryPoint

@AndroidEntryPoint
class GoodsDetailActivity : BaseToolbarActivity<MallGoodsViewModel, ActivityGoodsDetailBinding>() {
    override val mLayoutResId: Int
        get() = R.layout.activity_goods_detail
    private var mGoods: MallGoodsDetail? = null
    private val bannerList = ArrayList<String>()
    private val mViewModel : MallGoodsViewModel by viewModels()
    override fun initView() {
        super.initView()
//        val intent = Intent(this, GoodsDetailActivity::class.java)
//        val extra = intent.getIntExtra("goodsId", 1)
        mViewModel.getGoodsDetail()
    }

    override fun initData() {
        super.initData()
        mViewModel.goodsDetailLiveData.observe(this){
            mGoods = it
            mBinding.item = mGoods
            bannerList.clear()
            it.skuList.forEach {item->
                bannerList.add(item.skuImgUrl)
            }
            mBinding.vpTop.setImages(bannerList)
                .setImageLoader(object : ImageLoader() {
                    override fun displayImage(context: Context?, path: Any?, imageView: ImageView?) {
                        Glide.with(context!!).load(path).into(imageView!!)
                    }
                }).start()
        }

    }





}